package com.java110.acct.payment.adapt.pxlc.utils;

import net.sf.json.JSONArray;
import net.sf.json.JSONNull;
import org.apache.commons.lang3.StringUtils;

import java.util.Collection;
import java.util.Map;

public class ToolsUtil {
	@SuppressWarnings(value="all")
	public static boolean isBlank(Object obj) {
		if (obj == null || (("").equals(obj)) || (StringUtils.isBlank(obj.toString()))) {
			return true;
		}
		if (obj instanceof JSONNull) {
			return true;
		}
		if (obj instanceof JSONArray) {
			return ((JSONArray) obj).size() == 0;
		}
		if (obj instanceof CharSequence) {
			return ((CharSequence) obj).length() == 0;
		}

		if (obj instanceof Collection) {
			return ((Collection) obj).isEmpty();
		}

		if (obj instanceof Map) {
			return ((Map) obj).isEmpty();
		}
		if (obj instanceof Object[]) {
			Object[] object = (Object[]) obj;
			if (object.length == 0) {
				return true;
			}
			boolean empty = true;
			for (int i = 0; i < object.length; i++) {
				if (!isBlank(object[i])) {
					empty = false;
					break;
				}
			}
			return empty;
		}
		return false;
	}
	
	public static boolean isNotBlank(Object obj) {
		return !isBlank(obj);
	}
}
